const { task, src, dest } = require("gulp");
const htmlmin = require("gulp-htmlmin");
const cleanCSS = require("gulp-clean-css");
const terser = require("gulp-terser");

const { pipeline } = require("readable-stream");

task("default", (done) => {
	// process.chdir('.');

	const options = {
		removeComments: true,
		collapseWhitespace: true,
		removeRedundantAttributes: true,
		removeScriptTypeAttributes: true,
		removeStyleLinkTypeAttributes: true,
		minifyCSS: true,
		minifyJS: true,
	};

	src(["**/*.html", "!app/**"], {
		base: ".",
	})
		.pipe(htmlmin(options))
		.pipe(dest("."));

	src(["**/*.css", "!lib/**", "!app/**"], {
		base: ".",
	})
		.pipe(cleanCSS())
		.pipe(dest("."));

	pipeline(src(["**/js/*.js"], { base: "." }), terser(), dest("."));
	done();
});
